package com.hongkl.login;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.FormatFlagsConversionMismatchException;

/**
 * @author: hongkl
 * @Date: 2024/6/18 21:45
 * @Version: v1.0.0
 * @Description: TODO
 **/
public class LoginController {
    @FXML
    private Button btn_login;

    @FXML
    private Button btn_register;

    @FXML
    private TextField tf_username;
    
    @FXML
    private PasswordField pf_pwd;
    
    
    /**
     * 初始化方法
     */
    public void initialize(){
        System.out.println("initialize");
        try {
            BufferedReader reader = new BufferedReader(new FileReader("./data/user.json"));
            StringBuffer sb = new StringBuffer();
            String line;
            while((line = reader.readLine())!=null){
                sb.append(line);
            }

            reader.close();

            String jsonString = sb.toString();


            System.out.println(jsonString);

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

    public void btnLogin(){
        System.out.println("aaa");

        String username = tf_username.getText().toString();
        String pwd = pf_pwd.getText().toString();

        if (username.isEmpty()){
            System.out.println("用户名不能为空！");
        }else if (pwd.isEmpty()){
            System.out.println("密码不能为空！");
        }


    }

    public void btnRegister(){
        System.out.println("nbbb");
    }
}
